﻿#include "Hero.h"

Hero::Hero()
{
	this->m_Hp = 500;
	this->m_Atk = 50;
	this->m_Def = 50;
	this->m_Name = "刘法师";
	this->weapon = NULL;
}
//1.装备武器；
void Hero::EquipWeapon(Weapon* weapon)
{
	this->weapon = weapon;
	cout << "英雄：" << this->m_Name << " 装备了武器 << " << this->weapon->m_WeaponName << " >>" << endl;
}
//2.攻击；
void Hero::Attack(Monster* monster)
{
	int damage = 0;
	int suckHp = 0;
	bool isHold = false;
	bool isCrit = false;

	//3.武器为空，没有加成；
	if (this->weapon == NULL)
	{
		damage = this->m_Atk;
	}
	else
	{
		//4.基础伤害；
		damage = this->m_Atk + this->weapon->getBaseDamage();
		//5.计算吸血；
		suckHp = this->weapon->getSuckBlood();
		//6.计算定身；
		isHold = this->weapon->getHold();
		//7.计算暴击；
		isCrit = this->weapon->getCrit();
	}

	//8.遇到暴击，伤害加成；
	if (isCrit)
	{
		damage = damage * 2;
		cout << "英雄的武器触发了暴击效果，怪物受到了双倍的伤害，伤害值为：" << damage << endl;
	}

	if (isHold)
	{
		cout << "英雄的武器触发了定身效果，怪物停止攻击一回合。" << endl;
	}

	if (suckHp > 0)
	{
		cout << "英雄的武器触发了吸血效果，英雄增加的血量为：" << suckHp << endl;
	}

	//9.设置怪物定身；
	monster->isHold = isHold;
	//10.计算真实伤害；
	int trueDamage = (damage - monster->m_Def) > 0 ? damage - monster->m_Def : 1;

	monster->m_Hp -= trueDamage;
	this->m_Hp += suckHp;

	cout << "英雄" << this->m_Name << "攻击了敌人 " << monster->m_Name << "，造成了伤害：" << trueDamage << endl;
}
